package com.netty.rpc.consumer;

import com.netty.rpc.protocol.constants.ReqType;
import com.netty.rpc.protocol.constants.RpcConstant;
import com.netty.rpc.protocol.constants.SerialType;
import com.netty.rpc.protocol.core.Header;
import com.netty.rpc.protocol.core.RpcProtocol;
import com.netty.rpc.protocol.core.RpcRequest;
import com.netty.rpc.protocol.protocol.NettyClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class NettyRpcConsumerMain {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(NettyRpcConsumerMain.class, args);
        RpcProtocol<RpcRequest> protocol = new RpcProtocol<>();
        Header header = new Header(RpcConstant.MAGIC, SerialType.JAVA_SERIAL.code(), ReqType.REQUEST.code(), 1, 1);

        protocol.setHeader(header);
        RpcRequest rpcRequest = new RpcRequest();
        rpcRequest.setMethodName("com.netty.rpc.provider.service");
        rpcRequest.setClassName("UserServiceImpl");
        rpcRequest.setMethodName("saveUser");
        rpcRequest.setParameterTypes(new Class[]{String.class});
        rpcRequest.setParams(new Object[]{"hello netty"});
        protocol.setContent(rpcRequest);
        new NettyClient("127.0.0.1", 8080).sendRequest(protocol);   //case2(后续再加上)
    }
}